package com.devhelper.examples.gef.policy;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;

import com.devhelper.examples.gef.command.AbstractLayoutCommand;
import com.devhelper.examples.gef.command.DepartmentChangeLayoutCommand;
import com.devhelper.examples.gef.command.EmployeeChangeLayoutCommand;
import com.devhelper.examples.gef.part.DepartmentEditPart;
import com.devhelper.examples.gef.part.EmployeeEditPart;

public class ExEditLayoutPolicy extends XYLayoutEditPolicy {
    @Override
    protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
        AbstractLayoutCommand command = null;
        if (child instanceof EmployeeEditPart) {
            command = new EmployeeChangeLayoutCommand();
        } else if (child instanceof DepartmentEditPart) {
            command = new DepartmentChangeLayoutCommand();
        }

        command.setModel(child.getModel());
        command.setConstraint((Rectangle) constraint);
        return command;
    }

    @Override
    protected Command getCreateCommand(CreateRequest request) {
        // TODO Auto-generated method stub
        return null;
    }

}
